Skip to content

fix(upgrade): replace Bun.mmap with arrayBuffer on macOS to prevent SIGKILL#340

Merged
BYK merged 1 commit intomainfrom
fix/macos-delta-upgrade-sigkill
Mar 4, 2026
Merged

fix(upgrade): replace Bun.mmap with arrayBuffer on macOS to prevent SIGKILL#340
BYK merged 1 commit intomainfrom
fix/macos-delta-upgrade-sigkill

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 4, 2026

Summary

`Bun.mmap()` always requests `PROT_WRITE` in its implementation regardless of the `shared` flag. On macOS, AMFI code signing enforcement sends an uncatchable `SIGKILL` for any writable mapping (`MAP_SHARED` or `MAP_PRIVATE`) on code-signed Mach-O binaries — which all Bun-compiled binaries are.

PR #339's `{ shared: false }` (MAP_PRIVATE) fix was insufficient. Sentry telemetry confirmed: zero successful macOS upgrade traces from delta-enabled versions, while Linux worked fine.

Fix

Platform-conditional old file loading in `src/lib/bspatch.ts`:

  • macOS: `new Uint8Array(await Bun.file(oldPath).arrayBuffer())` — reads into memory (~100 MB heap, freed after patching)
  • Linux: `Bun.mmap(oldPath)` — keeps zero-heap memory-mapped path
const oldFile =
  process.platform === "darwin"
    ? new Uint8Array(await Bun.file(oldPath).arrayBuffer())
    : Bun.mmap(oldPath);

Evidence

Condition Upgrade Traces Outcome
macOS + pre-delta versions 26 ✅ All successful
macOS + delta-enabled versions 0 ❌ Process killed before telemetry flush
Linux + delta-enabled versions 4 ✅ All successful

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Trace

Other

  • (api) Add --data/-d flag and auto-detect JSON body in fields by BYK in #320
  • (formatters) Render all terminal output as markdown by BYK in #297
  • (install) Add Sentry error telemetry to install script by BYK in #334
  • (issue-list) Global limit with fair distribution, compound cursor, and richer progress by BYK in #306
  • (log-list) Add --trace flag to filter logs by trace ID by BYK in #329
  • (logger) Add consola-based structured logging with Sentry integration by BYK in #338
  • (project) Add project create command by betegon in #237
  • (upgrade) Add binary delta patching via TRDIFF10/bsdiff by BYK in #327

Bug Fixes 🐛

Api

  • Use numeric project ID to avoid "not actively selected" error by betegon in #312
  • Use limit param for issues endpoint page size by BYK in #309
  • Auto-correct ':' to '=' in --field values with a warning by BYK in #302

Formatters

  • Expand streaming table to fill terminal width by betegon in #314
  • Fix HTML entities and escaped underscores in table output by betegon in #313

Setup

  • Suppress agent skills and welcome messages on upgrade by BYK in #328
  • Suppress shell completion messages on upgrade by BYK in #326

Upgrade

  • Replace Bun.mmap with arrayBuffer on macOS to prevent SIGKILL by BYK in #340
  • Use MAP_PRIVATE mmap to prevent macOS SIGKILL during delta upgrade by BYK in #339

Other

  • (ci) Generate JUnit XML to silence codecov-action warnings by BYK in #300
  • (install) Fix nightly digest extraction on macOS by BYK in #331
  • (nightly) Push to GHCR from artifacts dir so layer titles are bare filenames by BYK in #301
  • (project create) Auto-correct dot-separated platform to hyphens by BYK in #336
  • (region) Resolve DSN org prefix at resolution layer by BYK in #316
  • (test) Handle 0/-0 in getComparator anti-symmetry property test by BYK in #308
  • (trace-logs) Timestamp_precise is a number, not a string by BYK in #323

Documentation 📚

  • Document SENTRY_URL and self-hosted setup by BYK in #337

Internal Changes 🔧

Api

  • Upgrade @sentry/api to 0.21.0, remove raw HTTP pagination workarounds by BYK in #321
  • Wire listIssuesPaginated through @sentry/api SDK for type safety by BYK in #310

Other

  • (craft) Add sentry-release-registry target by BYK in #325

🤖 This preview updates automatically when you update the PR.

@BYK BYK marked this pull request as ready for review March 4, 2026 20:28
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Codecov Results 📊

2681 passed | Total: 2681 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 3108 uncovered lines.
✅ Project coverage is 82.62%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    82.62%    82.62%        —%
==========================================
  Files          127       127         —
  Lines        17880     17883        +3
  Branches         0         0         —
==========================================
+ Hits         14772     14775        +3
- Misses        3108      3108         —
- Partials         0         0         —

Generated by Codecov Action

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

…IGKILL

Bun.mmap() always requests PROT_WRITE regardless of the `shared` flag.
On macOS, AMFI code signing enforcement sends an uncatchable SIGKILL for
ANY writable mapping (MAP_SHARED or MAP_PRIVATE) on code-signed Mach-O
binaries — which all Bun-compiled binaries are.

The previous fix (PR #339, { shared: false }) was insufficient because
MAP_PRIVATE with PROT_WRITE is also rejected. Sentry telemetry confirmed:
zero successful macOS upgrade traces from delta-enabled versions, while
Linux worked fine.

Use a platform check: on macOS, read the old binary into memory via
Bun.file().arrayBuffer() (~100 MB heap, freed after patching). On Linux,
keep the zero-heap Bun.mmap() path since ELF binaries have no such
restriction.
@BYK BYK force-pushed the fix/macos-delta-upgrade-sigkill branch from 10cfb5c to d6a972a Compare March 4, 2026 20:33
@BYK BYK merged commit feb415c into main Mar 4, 2026
20 checks passed
@BYK BYK deleted the fix/macos-delta-upgrade-sigkill branch March 4, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant